<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/27
 * Time: 18:10
 */
?>
<style type="text/css">
    #lbsMap {width: 600px;height: 400px;overflow: hidden;margin:0;margin-top: 20px}
</style>
<div>
    <ul class="breadcrumb">
        <li>
            <a href="<?php echo site_url('m-site')?>">管理首页</a> <span class="divider">/</span>
        </li>
        <li>
            <a href="javascript:void(0);" onclick="change_channel('marketing');">页面管理</a> <span class="divider">/</span>
        </li>
        <li>
            <a href="<?php echo site_url('m-site/marketing/page_index')?>">推荐列表</a> <span class="divider">/</span>
        </li>
        <li>
推荐详情
        </li>
    </ul>
</div>

<div class="row-fluid">
    <form class="form-horizontal" method="post"
          id="save_form"
          action="<?php if(isset($recommend['id'])){ ?>
          <?php echo site_url('m-admin/marketing/page_index/do_change_recommend'); }else{ ?>
          <?php echo site_url('m-admin/marketing/page_index/do_set_recommend'); } ?>"
          onsubmit="return false;">
        <fieldset>
            <legend>添加基本信息</legend>
            <div id="form_msg" class="alert" style="display: none;">
                <button type="button" class="close" onclick="$('#form_msg').hide();">×</button>
                <p></p>
            </div>

            <div class="control-group">
                <label class="control-label">请选择来源</label>
                <div class="controls" id="source_selector">
                    <select id="source" name="source" class="selector_root">
                        <option value="">请选择来源</option>
                        <?php foreach($source as $key=>$val) :?>
    <option value="<?php echo $key?>" <?php if(isset($recommend['source'])){
        if($recommend['source']==$key){
            echo 'selected="selected"';
        }
    } ?> >
        <?php echo $val['source_cn']?>
    </option>
<?php endforeach;?>
</select>
</div>
</div>

<div class="control-group">
    <label class="control-label">分类</label>
    <div class="controls" id="source_selector_label">
        <span class="label label-important selected_label"><?php if(isset($recommend['source_id'])){ ?>未更改<?php }else { ?>未选择<?php } ?></span>
        <input type="hidden" name="source_id" class="selected_id" value="<?php if(isset($recommend['source_id'])){echo $recommend['source_id'];} ?> >"/>
    </div>
</div>

<div class="control-group">
    <label class="control-label">请选择推荐方式</label>
    <div class="controls" id="zone_selector">
        <select id="func" name="func" class="selector_root">
            <option value="">请选择推荐方式</option>
            <?php foreach($func as $fun) :?>
                <option value="<?php echo $fun['func'];?>"
                    <?php if(@$recommend['func']==$fun['func']){ ?>
                        selected="selected"
                    <?php } ?> >
                    <?php echo $fun['func_cn'];?>
                </option>
            <?php endforeach;?>
        </select>
    </div>
</div>




<div class="control-group">
    <label class="control-label">排序值</label>
    <div class="controls">
        <input type="text" name="sorts" class="input-xlarge"  value="<?php if(@$recommend['sorts']){ echo $recommend['sorts']; }else{ ?>255<?php }?> "/>
    </div>
</div>


<div class="form-actions">
    <button id="save_form_btn" type="submit" class="btn btn-primary">保存</button>
    <?php if(isset($recommend['id'])){ ?>
        <input type="hidden" name="id"  value="<?php echo $recommend['id']; ?>" />
    <?php } ?>
    <input type="hidden" name="action" value="save" />
</div>
</fieldset>
</form>
</div>
<script type="text/javascript">
    $(document).ready(function() {

        var source_selector  = new Tree_selector('source_selector',
            '<?php echo site_url('/m-admin/Self_admin/gets')?>');
        source_selector.init();


        $('#establish_date').datepicker({ dateFormat: 'yy-mm-dd' });

        $('#save_form_btn').click(function() {
            var btn = $(this);
            var form_id = 'save_form';

            btn.prop('disabled', true);
            var options = {
                dataType: 'json',
                success: function(response) {
                    if(response.status) {
                        <?php if(isset($recommend['id'])){ ?>
                        window.location.href='<?php echo site_url('m-site/marketing/page_index'); ?>';
                        <?php }else{ ?>
                        success_msg_show('form_msg', '操作成功！您可以继续操作');
                        $('#' + form_id).resetForm();
                        source_selector.resetSelector();
                        <?php }?>
                    }else if(!response.status) {
                        error_msg_show('form_msg', response.msg);
                    } else {
                        alert('操作失败，请重试或联系管理员！');
                        console.log(response);
                    }
                    btn.prop('disabled', false);
                }
            };
            $('#' + form_id).ajaxSubmit( options );
            return false;
        });

    });

</script>
